class ScorePanel {
    private _level = 1;
    private _score = 0;
    private scoreEle: HTMLElement;
    private levelEle: HTMLElement;

    // 设置一个变量限制等级
    private maxLevel: number;
    // 设置一个变量表示多少分时升级
    private upScore: number;

    constructor(maxLevel: number, upScore: number) {
        this.scoreEle = document.getElementById("score");
        this.levelEle = document.getElementById("level");
        this.maxLevel = maxLevel;
        this.upScore = upScore;
    }

    addScore() {
        this.scoreEle.innerHTML = ++this._score + "";
        if (this._score % this.upScore === 0) {
            this.levelUp();
        }
    }

    get level(): number {
        return this._level;
    }

    private levelUp() {
        if (this.level < this.maxLevel) {
            this.levelEle.innerHTML = ++this._level + "";
        }
    }
}

export default ScorePanel;